From 5bbe71e660015f913152966ab8201ed9a439c42e Mon Sep 17 00:00:00 2001
From: robertl
Date: Wed, 14 Nov 2007 16:43:24 +0000
Subject: [PATCH] Several changes to KML writer. Major formatting
improvements for geocaching.com data. (Relies on Earth 4.2) Don't write
track/route folders if empty. Don't write explicit schemaloc.
git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@3016 f51c46e8-681c-474f-0cfe-069cfd0219fb
---
gpsbabel/defs.h | 1 +
gpsbabel/kml.c | 270 ++++++++++++++++++-------
gpsbabel/reference/earth-expertgps.kml | 4 +-
gpsbabel/reference/earth-gc.kml | 173 +++++++++-------
gpsbabel/waypt.c | 11 +
5 files changed, 311 insertions(+), 148 deletions(-)
diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h
index 47bd4b2fe..49850aa73 100644
--- a/gpsbabel/defs.h
+++ b/gpsbabel/defs.h
@@ -180,6 +180,7 @@ extern global_options global_opts;
extern const char gpsbabel_version[];
extern time_t gpsbabel_now; /* gpsbabel startup-time; initialized in main.c with time() */
extern time_t gpsbabel_time; /* gpsbabel startup-time; initialized in main.c with current_time(), ! ZERO within testo ! */
+extern int geocaches_present;
#define MILLI_TO_MICRO(t) (t * 1000) /* Milliseconds to Microseconds */
#define MICRO_TO_MILLI(t) (t / 1000) /* Microseconds to Milliseconds*/
diff --git a/gpsbabel/kml.c b/gpsbabel/kml.c
index e9896153a..f90e62264 100644
--- a/gpsbabel/kml.c
+++ b/gpsbabel/kml.c
@@ -69,6 +69,20 @@ static int do_indentation = 1;
#define TD(FMT,DATA) kml_write_xml(0, "| " FMT " |
\n", DATA)
#define TD2(FMT,DATA, DATA2) kml_write_xml(0, "| " FMT " |
\n", DATA, DATA2)
+static const char kml22_hdr[] =
+ "\n";
+// No "baked in" schemaLocation, per Google recommendation.
+// "\txsi:schemaLocation=\"http://earth.google.com/kml/2.2 \n"
+// "\thttp://code.google.com/apis/kml/schema/kml22beta.xsd\">\n";
+
+static const char kml21_hdr[] =
+ "\n";
+// No "baked in" schemaLocation, per Google recommendation.
+// "\txsi:schemaLocation=\"http://earth.google.com/kml/2.1 \n"
+// "\thttp://code.google.com/apis/kml/schema/kml21.xsd\">\n";
+
static
arglist_t kml_args[] = {
{"deficon", &opt_deficon, "Default icon name", NULL, ARGTYPE_STRING, ARG_NOMINMAX },
@@ -214,7 +228,7 @@ void trk_coord(const char *args, const char **attrv)
}
track_add_head(trk_head);
- while (3 == sscanf(args,"%lf,%lf,%lf %n", &lon, &lat, &alt, &consumed)){
+ while (3 == sscanf(args, "%lf,%lf,%lf %n", &lon, &lat, &alt, &consumed)){
trkpt = waypt_new();
trkpt->latitude = lat;
trkpt->longitude = lon;
@@ -363,7 +377,7 @@ kml_write_xmle(const char *tag, const char *v)
static void kml_write_bitmap_style_(const char *style, const char * bitmap,
int highlighted)
{
- kml_write_xml(0,"\n",
+ kml_write_xml(0, "\n",
highlighted ? "Highlighted" : "Normal", style);
kml_write_xml(1, "\n");
+}
+
static
char *
kml_lookup_gc_icon(const waypoint *waypointp)
@@ -689,6 +724,112 @@ kml_lookup_gc_icon(const waypoint *waypointp)
return rb;
}
+static
+char *
+kml_lookup_gc_container(const waypoint *waypointp)
+{
+ char *cont;
+
+ switch (waypointp->gc_data.container) {
+ case gc_micro: cont="micro"; break;
+ case gc_regular: cont="regular"; break;
+ case gc_large: cont="large"; break;
+ case gc_small: cont="small"; break;
+ case gc_virtual: cont="virtual"; break;
+ case gc_other: cont="other"; break;
+ default: cont="not_chosen"; break;
+ }
+
+ return cont;
+}
+
+// Not thread safe. Return strings are small and it's silly to xasprintf/free
+// them so we use a static buffer.
+
+char * kml_gc_mkstar(int rating)
+{
+ static char tmp[40];
+ if (0 == rating % 10) {
+ snprintf(tmp, sizeof(tmp), "stars%d", rating / 10);
+ } else {
+ snprintf(tmp, sizeof(tmp), "stars%d_%d", rating / 10, rating % 10);
+ }
+
+ return tmp;
+}
+
+static void kml_geocache_pr(const waypoint *waypointp)
+{
+ char *p, *is;
+
+ kml_write_xml(1, "\n");
+
+ kml_write_xml(1, "\n");
+ kml_write_xml(0, "\n", waypointp->url_link_text);
+ kml_write_xml(-1, "\n");
+
+ // Timestamp
+ kml_output_timestamp(waypointp);
+
+ kml_write_xml(0, "#geocache\n");
+ is = kml_lookup_gc_icon(waypointp);
+ kml_write_xml(1, "\n");
+
+ kml_write_xml(1, "\n");
+ kml_write_xml(0, "%s\n", waypointp->shortname);
+
+ p = xml_entitize(waypointp->url_link_text);
+ kml_write_xml(0, "%s\n", p);
+ xfree(p);
+
+ p = xml_entitize(waypointp->gc_data.placer);
+ kml_write_xml(0, "%s\n", p);
+ xfree(p);
+
+ kml_write_xml(0, "%d\n", waypointp->gc_data.placer_id);
+
+ kml_write_xml(0, "%s\n", kml_gc_mkstar(waypointp->gc_data.diff));
+ kml_write_xml(0, "%s\n", kml_gc_mkstar(waypointp->gc_data.terr));
+
+ kml_write_xml(0, "%s\n", kml_lookup_gc_container(waypointp));
+
+ // Highlight any issues with the cache, such as temp unavail
+ // or archived.
+ kml_write_xml(0, "");
+ if (waypointp->gc_data.is_archived == 1) {
+ kml_write_xml(0, "<font color=\"red\">This cache has been archived.</font>
\n");
+ } else if (waypointp->gc_data.is_available == 0) {
+ kml_write_xml(0, "<font color=\"red\">This cache is temporarily unavailable.</font>
\n");
+ }
+ kml_write_xml(0, "\n");
+
+ kml_write_xml(0, "%s\n", gs_get_cachetype(waypointp->gc_data.type));
+ kml_write_xml(0, "\n", waypointp->gc_data.desc_short.utfstring ? waypointp->gc_data.desc_short.utfstring : "");
+ kml_write_xml(0, "\n", waypointp->gc_data.desc_long.utfstring ? waypointp->gc_data.desc_long.utfstring : "");
+
+ kml_write_xml(-1, "\n");
+
+ // Location
+ double lat = waypointp->latitude;;
+ double lng = waypointp->longitude;
+// optionally "fuzz" lat/lng here.
+ kml_write_xml(1, "\n");
+ kml_write_xml(0, "%f,%f,%f\n",
+ lng, lat,
+ waypointp->altitude == unknown_alt ? 0.0 : waypointp->altitude);
+
+ kml_write_xml(-1, "\n");
+ kml_write_xml(-1, "\n");
+
+ xfree(is);
+}
+
/*
* WAYPOINTS
*/
@@ -697,6 +838,11 @@ static void kml_waypt_pr(const waypoint *waypointp)
{
const char *icon;
+ if (waypointp->gc_data.diff && waypointp->gc_data.terr) {
+ kml_geocache_pr(waypointp);
+ return;
+ }
+
kml_write_xml(1, "\n");
kml_write_xmle("name", waypointp->shortname);
@@ -704,40 +850,16 @@ static void kml_waypt_pr(const waypoint *waypointp)
// Description
if (waypointp->url && waypointp->url[0]) {
char * odesc = xml_entitize(waypointp->url);
- kml_write_xml(0,"\n");
- kml_write_xml(0,"\n");
+ kml_write_xml(0, "\n");
+ kml_write_xml(0, "\n");
if (waypointp->url_link_text && waypointp->url_link_text[0]) {
char *olink = xml_entitize(waypointp->url_link_text);
- kml_write_xml(0,"%s]]>", odesc, olink);
+ kml_write_xml(0, "%s]]>", odesc, olink);
xfree(olink);
- }
- else
+ } else {
fputs(odesc, ofd);
-
- /* It's tempting to conditionalize this on smart_names, but
- * KML is so robust that it makes sense to just always do
- * this for geocaches. (Plus the convenience of being able
- * to do a drag-n-drop into Earth without extra option is a
- * win.)
- */
- if (waypointp->gc_data.diff && waypointp->gc_data.terr) {
- if (waypointp->gc_data.placer) {
- char *p = xml_entitize(waypointp->gc_data.placer);
- fprintf(ofd, " by %s]]>", p);
- xfree(p);
- }
- fprintf(ofd, " %s (%3.1f/%3.1f)",
- gs_get_container(waypointp->gc_data.container),
- waypointp->gc_data.diff / 10.0,
- waypointp->gc_data.terr / 10.0);
- if (waypointp->gc_data.desc_short.utfstring) {
- // Dont entitize it - either XML or HTML.
- // Wrap it in a cdata and let Earth work it out.
-
- fprintf(ofd, "%s
]]>\n", waypointp->gc_data.desc_short.utfstring);
-
- }
}
+
kml_write_xml(0, "\n");
xfree(odesc);
}
@@ -755,17 +877,6 @@ static void kml_waypt_pr(const waypoint *waypointp)
kml_write_xml(-1, "\n");
kml_write_xml(-1, "\n");
kml_write_xml(-1, "\n");
-
- } else if (waypointp->gc_data.diff && waypointp->gc_data.terr) {
- char *is = kml_lookup_gc_icon(waypointp);
- kml_write_xml(1, "\n");
- xfree(is);
} else {
kml_write_xml(0, "#waypoint\n");
}
@@ -774,11 +885,11 @@ static void kml_waypt_pr(const waypoint *waypointp)
kml_write_xml(1, "\n");
if (extrude) {
- kml_write_xml(0, "1\n");
+ kml_write_xml(0, "1\n");
}
if (floating) {
- kml_write_xml(0, "absolute\n");
+ kml_write_xml(0, "absolute\n");
}
kml_write_xml(0, "%f,%f,%f\n",
@@ -786,8 +897,6 @@ static void kml_waypt_pr(const waypoint *waypointp)
waypointp->altitude == unknown_alt ? 0.0 : waypointp->altitude);
kml_write_xml(-1, "\n");
-
-
kml_write_xml(-1, "\n");
}
@@ -844,13 +953,22 @@ void kml_write(void)
extrude = (!! strcmp("0", opt_extrude));
trackdata = (!! strcmp("0", opt_trackdata));
- kml_write_xml(0,"\n");
- kml_write_xml(1,"\n"
- );
- kml_write_xml(1,"\n");
+ kml_write_xml(0, "\n");
+
+ /*
+ * This is a bit cowardly. Our geocache writer takes advantage
+ * of KML 2.2 features present only in Earth 4.2 and newer. The
+ * output is actually compatible with Earth versions back to 4.0
+ * for the non-geocaching case, so we'll be conservative and not
+ * output the new namespace if we don't need it.
+ */
+ if (geocaches_present) {
+ kml_write_xml(1, kml22_hdr);
+ } else {
+ kml_write_xml(1, kml21_hdr);
+ }
+
+ kml_write_xml(1, "\n");
now = current_time();
strftime(import_time, sizeof(import_time), "%c", localtime(&now));
@@ -864,17 +982,29 @@ void kml_write(void)
}
// Style settings for bitmaps
- kml_write_bitmap_style("route", "http://maps.google.com/mapfiles/kml/pal4/icon61.png");
- kml_write_bitmap_style("track", "http://maps.google.com/mapfiles/kml/pal4/icon60.png");
+ if (route_waypt_count()) {
+ kml_write_bitmap_style("route", "http://maps.google.com/mapfiles/kml/pal4/icon61.png");
+ }
+
+ if (track_waypt_count()) {
+ kml_write_bitmap_style("track", "http://maps.google.com/mapfiles/kml/pal4/icon60.png");
+ }
+
kml_write_bitmap_style("waypoint", "http://maps.google.com/mapfiles/kml/pal4/icon61.png");
- // Style settings for line strings
- kml_write_xml(1, "\n");
+ if (track_waypt_count() || route_waypt_count()) {
+ // Style settings for line strings
+ kml_write_xml(1, "\n");
+ }
+
+ if (geocaches_present) {
+ kml_gc_make_ballonstyle();
+ }
if (!realtime_positioning) {
kml_write_xml(1, "\n");
diff --git a/gpsbabel/reference/earth-expertgps.kml b/gpsbabel/reference/earth-expertgps.kml
index 730bb4a99..f0aa709f8 100644
--- a/gpsbabel/reference/earth-expertgps.kml
+++ b/gpsbabel/reference/earth-expertgps.kml
@@ -1,8 +1,6 @@
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
GPS device
diff --git a/gpsbabel/reference/earth-gc.kml b/gpsbabel/reference/earth-gc.kml
index 2f3a41c8d..8b1d8a2c2 100644
--- a/gpsbabel/reference/earth-gc.kml
+++ b/gpsbabel/reference/earth-gc.kml
@@ -1,64 +1,8 @@
-
+
GPS device
-
-
-
-
-
-
- normal
- #route_n
-
-
- highlight
- #route_h
-
-
-
-
-
-
-
-
- normal
- #track_n
-
-
- highlight
- #track_h
-
-
+
Waypoints
- GC7FA4
-
-
-Points géodésiques du Québec]]> by Sverdrup2]]> Virtual (1.0/1.0)LES COORDONÃES PUBLIÃES NE REPRÃSENTENT PAS LA LOCALISATION D'UNE CACHE
-PUBLISHED COORDINATES DO NOT REPRESENT THE LOCALIZATION OF A CACHE]]>
-
+
+
+
2002-08-15T07:00:00Z
+ #geocache
+
+ GC7FA4
+ Points géodésiques du Québec
+ Sverdrup2
+ 6293
+ stars1
+ stars1
+ virtual
+
+ Locationless (Reverse) Cache
+
+
+Pour inscrire votre découverte, vous devez prendre en note le NUMÃRO DU POINT(inscrit sur le point même ou au centre du panneau)LA COORDONNÃE(en format HDDD MM.MM WGS84 datum ET UTM NAD83 indiquer la zone SVP)et L'ALTITUDE RELATIVE. Si le points n'est pas visible (il se peut qu'il soit sous quelques centimètres de terre) vous pouvez prendre la coordonnée à l'emplacement du panneau SI LA PRÃCISION DE VOTRE GPS EST SUPÃRIEUR à LA DISTANCE INSCRITE SUR LE PANNEAU (ex : Précison du GPS de 5m et distance au point inscrite sur le panneau de 3m).
+
+Une photo du point ou du panneau et une description générale des lieux serait aussi des informations importantes.
+
+Enfin, il faudrait aussi prendre en note l'organisme propriétaire du point géodésique. Au Québec il en existe plusieurs:
+
+Le Service de la géodésie du Québec, Ministère des Ressources naturelles, Québec
+
+La Division des levés géodésiques, Géomatique Canada, Secteur des sciences de la terre Ressources naturelles Canada
+
+Le Service hydrographique du Canada, Direction des sciences, Pêches et Océans Canada et la Garde côtière canadienne, Pêches et Océans Canada
+
+Et tout les anciens noms de ministères et/ou organisme
+
+Des photos de points de même que des panneaux suivront bientôt.
+VOUS NE POUVEZ INSCRIRE QU'UN SEUL POINT GÃODÃSIQUE (UN POINT PAR GÃOCACHEUR)
+Bonne chance!
+
+
+
+The goal of this virtual cache is to find the geodetic points of Québecâs territory. The geodetic points are easy to identify (Brass cap at ground level) Generally, there is an orange panel of on a post near the point. On this panel, the number of the point is identified. Also, the distance relating from the panel to the point is also indicated. In order to log your find, you must take in note THE NUMBER OF THE POINT(registered on the point or in the center of the panel) and THE COORDINATES(in format HDDD MM.MM WGS84 datum AND UTM NAD83 indicate the zone please)and THE ALTITUDE. If the point is not visible (it may be buried under few centimetres) you can take the coordinate at the panel IF THE ACCURACY OF YOUR GPS IS HIGHER Than the DISTANCE REGISTERED ON the PANEL. (Ex: accuracy of the GPS is 5m and the distance to the point registered on the panel is 3m).
+
+A picture of the point or panel and a general description of the places would be also significant information. Finally, it would also be important to take in note the organization owner of the geodetic point.
+In Quebec there are several:
+
+The "Service de la géodésie du Québec, Ministère des Ressources naturelles Québec"
+The Geodetic Survey Division, Geomatics Canada, Earth Sciences Sector, Natural Resources Canada
+The Canadian Hydrographic Service, Sciences Directorate, Fisheries and Oceans Canada and the Canadian Coast Guard, Fisheries and Oceans Canada
+And all old names of ministries and/or organization
+
+
+PICTURES of points and of the panels will follow soon. YOU CAN ONLY LOG ONE POINT (ONE POINT PER GEOCACHER)
+Good luck!]]>
+
-73.000000,46.133333,0.000000
- GCGCA8
-
-
-Oozy rat in a sanitary zoo]]> by robertlipe]]> Unknown (3.0/2.0)The cache is not at the coordinates above. These coords will get you to the correct park and within 1/2 mile of the cache. The cache is within 35 feet of the trail. It is not handicapped accessible. It is a nice walk in the woods that is practical for all ages. There is no space in the container for trading items. You should bring a writing stick and bug spray is recommended.]]>
-
+
+
+
2003-06-29T07:00:00Z
+ #geocache
+
+ GCGCA8
+ Oozy rat in a sanitary zoo
+ robertlipe
+ 32733
+ stars3
+ stars2
+ not_chosen
+
+ Unknown Cache
+
+
+
+Too bad I hid a boot
+Too hot to hoot
+Never odd or even
+Do geese see God?
+"Do nine men interpret?" "Nine men," I nod
+Rats live on no evil star
+Go hang a salami, I'm a lasagna hog
+
+
+Now that it's intuitively obvious to even the most casual observer where the cache is, turn on your geo-mojo and go find it.
+
+
]]>
+
-86.861667,35.921667,0.000000
diff --git a/gpsbabel/waypt.c b/gpsbabel/waypt.c
index b6f89c075..b1d49e3db 100644
--- a/gpsbabel/waypt.c
+++ b/gpsbabel/waypt.c
@@ -28,6 +28,7 @@
queue waypt_head;
static unsigned int waypt_ct;
static short_handle mkshort_handle;
+int geocaches_present;
void
waypt_init(void)
@@ -141,6 +142,16 @@ waypt_add(waypoint *wpt)
}
}
}
+
+ /* This is a bit tacky, but it allows a hint whether we've seen
+ * geocaches or not in the life cycle of this run. Of course,
+ * the caches could have been filtered out of existance and not
+ * all waypoints may have this and a few other pitfalls, but it's
+ * an easy and fast test here.
+ */
+ if (wpt->gc_data.diff && wpt->gc_data.terr) {
+ geocaches_present = 1;
+ }
}
void
--
2.30.2